package com.driving.single.common.redis.service.impl;

import com.driving.single.common.entity.LoginResult;
import com.driving.single.common.redis.service.CommonRedisUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class CommonRedisUserServiceImpl implements CommonRedisUserService {
    @Value("${redis_key_sso_user}")
    private String redis_key_sso_user;
    @Value("${redis_key_sso_user_expire_second}")
    private Integer redis_key_sso_user_expire_second;


    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    /**
     * 用户登录模型插入到Redis中
     * @param loginResult 用户登录模型
     */
    @Override
    public Integer addUserLoginResultToRedis(LoginResult loginResult) {
        String key = redis_key_sso_user + ":" + loginResult.getUserid();
        this.redisTemplate.opsForValue().set(key, loginResult, this.redis_key_sso_user_expire_second,
                TimeUnit.SECONDS);
        return 200;
    }
}
